package com.yanqu.road.server.cmd.patrons;

import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.logic.pb.PatronsPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.patrons.CombLeaderProto;
import com.yanqu.road.pb.patrons.PatronsProto;
import com.yanqu.road.pb.vehicle.VehicleProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.patrons.CombLeaderModule;
import com.yanqu.road.server.gameplayer.module.patrons.PatronsModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_COMB_LEADER_CHOOSE_LEADER, desc = "组合选择首领")
public class CombLeaderChooseCmd extends AbstractCommand {

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		CombLeaderProto.CombLeaderChoseLeaderReqMsg reqMsg = CombLeaderProto.CombLeaderChoseLeaderReqMsg.parseFrom(packet.getBytes());
		ret = player.getModule(CombLeaderModule.class).chooseLeader(reqMsg.getCombId(), reqMsg.getLeaderId());
	}

	@Override
	public void sendData(GamePlayer player) {
		if (ret != 0) {
			//获得注解的code
			int code = this.getClass().getAnnotation(Cmd.class).code();
			int backClientProtocol = code % 10000;
			player.sendPacket(backClientProtocol, VehicleProto.VehicleBoneLvUpRespMsg.newBuilder().setRet(ret));
		}
	}
}
